package logic

import (
	"context"
	"fmt"
	"rpc/model/mysql"

	"rpc/internal/svc"
	"rpc/turn"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsUpdateStatusLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsUpdateStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsUpdateStatusLogic {
	return &GoodsUpdateStatusLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsUpdateStatusLogic) GoodsUpdateStatus(in *turn.GoodsUpdateStatusRequest) (*turn.GoodsUpdateStatusResponse, error) {
	// todo: add your logic here and delete this line

	g := mysql.Goods{}
	err := g.UpdateStatus(in.GoodsId, in.Status)
	if err != nil {
		return nil, fmt.Errorf("修改失败")
	}

	return &turn.GoodsUpdateStatusResponse{Success: true}, nil
}
